﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tracker.Models.BLL;
using tracker.Models;
using System.Data;
using tracker.Models.DTO;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Threading;
using System.Text;
using System.Resources;

namespace tracker.Controllers
{
   public class HandlerExcelController : Controller
    {
       /// <summary>
       /// Get All Alarm Define
       /// </summary>
       /// <returns></returns>
       [CallAjaxFilter]
       public void Index(string exceltype,
                         string start,
                         string limit,
                         string trackName,
                         string alarmId,
                         string fromtime,
                         string totime,
                         string requestaddress,
                         string speedCompare,
                         string speedNumber,
                         string Length,
                         string snid,
                         string startspeed,
                         string stopminutes,
                         string distance,
                         string name)
       {
           string result = "";
           string _username = HttpContext.Session[Common.USER].ToString();
           string _language = HttpContext.Session[Common.LANGUAGE].ToString();
           string timezone = HttpContext.Session[Common.TIMEZONE].ToString();
           _language = _language == string.Empty ? "vi" : _language;

           List<ENTTrackerName> listTrackerName = new List<ENTTrackerName>();
           listTrackerName = HandlerSearchTrackerNameController.getListDeviceByUser(_username);

           string username = "";
           foreach (ENTTrackerName item in listTrackerName)
           {
               username += item.username + ",";
           }
           username = username.Remove(username.LastIndexOf(","));

           #region ALARM
           if (exceltype == "alarm")
           {
               DataTable dtData = TrackLogBLL.GetRecodeBySearchAlarm(new string[]{"AlarmId",
                                                                                   "TrackName",
                                                                                   "Start",
                                                                                   "End",
                                                                                   "FromTime",
                                                                                   "ToTime",
                                                                                   "UserName"},
                                                                     new object[]{alarmId,
                                                                                   trackName,
                                                                                   int.Parse(start),
                                                                                   int.Parse(limit),
                                                                                   ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(fromtime),timezone),
                                                                                   ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(totime),timezone),
                                                                                   username}).Tables[0];
               if (dtData.Rows.Count > 0)
               {
                   DataTable dtDataSet = setHeader("alarm", _language);

                   foreach (DataRow item in dtData.Rows)
                   {
                       DataRow dtr = dtDataSet.NewRow();
                       dtr[0] = item[EAlarmSearch._DeviceName].ToString();
                       dtr[1] = getResouceByName("A" + item[EAlarmSearch._AlarmTypeID].ToString(), _language);
                       dtr[2] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(item[EAlarmSearch._Gps_time].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                       dtr[3] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(item[EAlarmSearch._RecieveTime].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                       dtr[4] = item[EAlarmSearch._Gps_status].ToString().ToLower() == "valid" ? getResouceByName("lbFix", _language) : getResouceByName("lbNoFix", _language);
                       dtr[5] = item[EAlarmSearch._Latitude].ToString();
                       dtr[6] = item[EAlarmSearch._Longitude].ToString();
                       if (requestaddress == "1")
                       {
                           dtr[7] = string.Empty;//getAddress(item[EAlarmSearch._Latitude].ToString(), item[EAlarmSearch._Longitude].ToString());
                       }
                       dtr[8] = item[EAlarmSearch._Speed].ToString();

                       dtDataSet.Rows.Add(dtr);
                   }

                   Response.ClearContent();
                   Response.Buffer = true;
                   Response.AddHeader("content-disposition", "attachment; filename=" + convertTextToFileName(trackName, "alarm", ".xls"));
                   Response.ContentType = "application/ms-excel";

                   Response.Charset = "";
                   System.IO.StringWriter sw = new System.IO.StringWriter();
                   System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

                   var grid = new GridView();
                   grid.DataSource = dtDataSet;
                   grid.DataBind();
                   grid.RenderControl(htw);

                   Response.Output.Write(sw.ToString());
                   Response.Flush();
                   Response.End();

               }
           }
           #endregion

           #region HISTORY
           else if (exceltype == "history")
           {
               DataTable dtData = null;

               if (speedCompare == ">=")
                   dtData = TrackLogBLL.GetRecodeBySearchSpeedAlarmMoreThanExcel(new string[]{"SpeedNumber",
                                                                                               "TrackName",
                                                                                               "Start",
                                                                                               "End",
                                                                                               "FromTime",
                                                                                               "ToTime",
                                                                                               "UserName"
                                                                                    },
                                                                                  new object[]{float.Parse(speedNumber),
                                                                                                trackName,
                                                                                                start, 
                                                                                                start + limit  , 
                                                                                                ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(fromtime),timezone),
                                                                                                ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(totime),timezone),
                                                                                                username
                                                                                   }).Tables[0];
               else
                   dtData = TrackLogBLL.GetRecodeBySearchSpeedAlarmLessThanExcel(new string[]{"SpeedNumber",
                                                                                                "TrackName",
                                                                                                "Start",
                                                                                                "End",
                                                                                                "FromTime",
                                                                                                "ToTime",
                                                                                                "UserName"
                                                                                    },
                                                                                   new object[]{float.Parse(speedNumber),
                                                                                                trackName,
                                                                                                start, 
                                                                                                start + limit  , 
                                                                                                ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(fromtime),timezone),
                                                                                                ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(totime),timezone),
                                                                                                username
                                                                                    }).Tables[0];


               if (dtData.Rows.Count > 0)
               {
                   DataTable dtDataSet = setHeader("history", _language);

                   foreach (DataRow item in dtData.Rows)
                   {
                       DataRow dtr = dtDataSet.NewRow();
                       dtr[0] = item[EAlarmSearch._DeviceName].ToString();
                       dtr[1] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(item[EAlarmSearch._Gps_time].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                       dtr[2] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(item[EAlarmSearch._RecieveTime].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                       dtr[3] = item[EAlarmSearch._Gps_status].ToString().ToLower() == "valid" ? getResouceByName("lbFix", _language) : getResouceByName("lbNoFix", _language);
                       if (requestaddress == "1")
                       {
                           dtr[6] = string.Empty;//getAddress(item[EAlarmSearch._Latitude].ToString(), item[EAlarmSearch._Longitude].ToString());
                       }
                       dtr[4] = item[EAlarmSearch._Latitude].ToString();
                       dtr[5] = item[EAlarmSearch._Longitude].ToString();
                       dtr[7] = item[EAlarmSearch._Speed].ToString();
                       dtr[8] = getResouceByName("A" + item[EAlarmSearch._AlarmTypeID].ToString(), _language);
                       dtr[9] = item[EAlarmSearch._Hdop].ToString();
                       dtr[10] = item[EAlarmSearch._High].ToString();
                       dtr[11] = item[EAlarmSearch._Angle].ToString();
                       dtr[12] = item[EAlarmSearch._Journey].ToString();
                       dtr[13] = item[EAlarmSearch._RunTime].ToString();
                       dtr[14] = item[EAlarmSearch._Satellites].ToString();
                       dtr[15] = item[EAlarmSearch._Gsm_Signal].ToString();

                       dtDataSet.Rows.Add(dtr);
                   }

                   Response.ClearContent();
                   Response.Buffer = true;
                   Response.AddHeader("content-disposition", "attachment; filename=" + convertTextToFileName(trackName, "history", ".xls"));
                   Response.ContentType = "application/ms-excel";

                   Response.Charset = "";
                   System.IO.StringWriter sw = new System.IO.StringWriter();
                   System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

                   var grid = new GridView();
                   grid.DataSource = dtDataSet;
                   grid.DataBind();
                   grid.RenderControl(htw);

                   Response.Output.Write(sw.ToString());
                   Response.Flush();
                   Response.End();
               }
           }
           #endregion
           #region Parking
           else if (exceltype == "parkingall")
           {
               string timeLength = Length;
               string snids = snid;

               DataTable dtDataSet = setHeader("parkingall", _language);

               int minuteTime = 0;

               string[] sHours = timeLength.Split(':');
               minuteTime = int.Parse(sHours[0]) * 60 + int.Parse(sHours[1]);

               DataTable dtData = DistanceLogBLL.GetAllPartInfo(new string[]{"minuteTime",
                                                                                          "Start",
                                                                                          "End",
                                                                                          "snids",
                                                                                          "FromTime",
                                                                                          "ToTime",
                                                                                          "Username"
                                                                              },
                                                                 new object[]{minuteTime,
                                                                                           int.Parse(start),
                                                                                           int.Parse(start + limit),
                                                                                           snids,
                                                                                           ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(fromtime),timezone),
                                                                                           ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(totime),timezone),
                                                                                           username
                                                                              }).Tables[0];

               foreach (DataRow item in dtData.Rows)
               {
                   DataRow dtr = dtDataSet.NewRow();

                   dtr[0] = item["DeviceName"].ToString();
                   dtr[1] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(dtData.Rows[0]["TimeBegin"].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                   dtr[2] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(dtData.Rows[0]["TimeEnd"].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                   dtr[3] = item["LatitudeEnd"].ToString();
                   dtr[4] = item["LongitudeEnd"].ToString();
                   if (requestaddress == "1")
                   {
                       dtr[5] = string.Empty;//getAddress(item["LatitudeEnd"].ToString(), item["LongitudeEnd"].ToString());
                   }
                   dtr[6] = item["TimeMinutes"].ToString();
                   dtDataSet.Rows.Add(dtr);
               }

               if (dtDataSet.Rows.Count > 0)
               {
                   Response.ClearContent();
                   Response.Buffer = true;
                   Response.AddHeader("content-disposition", "attachment; filename=" + convertTextToFileName(snids, "parkingall", ".xls"));
                   Response.ContentType = "application/ms-excel";

                   Response.Charset = "";
                   System.IO.StringWriter sw = new System.IO.StringWriter();
                   System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

                   var grid = new GridView();
                   grid.DataSource = dtDataSet;
                   grid.DataBind();
                   grid.RenderControl(htw);

                   Response.Output.Write(sw.ToString());
                   Response.Flush();
                   Response.End();
               }
           }
           #endregion
           #region Distance all
           else if (exceltype == "distanceall")
           {
               string snids = snid;
               string Getname = name;

               DataTable dtDataSet = setHeader("distanceall", _language);

               DataTable dtData = DistanceLogBLL.GetAllPartInfoReport(new string[]{"distance",
                                                                                    "Start",
                                                                                    "End",
                                                                                    "snids",
                                                                                    "FromTime",
                                                                                    "ToTime",
                                                                                    "Username",
                                                                                    "StartSpeed"
                                                                        },
                                                                       new object[]{distance,
                                                                                     int.Parse(start),
                                                                                     int.Parse(start + limit),
                                                                                     snids,
                                                                                     ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(fromtime),timezone),
                                                                                     ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(totime),timezone),
                                                                                     username,
                                                                                     float.Parse(startspeed)
                                                                                    }).Tables[0];

               foreach (DataRow item in dtData.Rows)
               {
                   DataRow dtr = dtDataSet.NewRow();

                   dtr[0] = item["DeviceName"].ToString();
                   dtr[1] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(dtData.Rows[0]["TimeBegin"].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                   dtr[2] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(dtData.Rows[0]["TimeEnd"].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                   dtr[3] = item["TimeMinutes"].ToString();
                   if (requestaddress == "1")
                   {
                       dtr[4] = string.Empty;//getAddress(item["LatitudeBegin"].ToString(), item["LongitudeBegin"].ToString());
                       dtr[5] = string.Empty;// getAddress(item["LatitudeEnd"].ToString(), item["LongitudeEnd"].ToString());
                   }
                   else
                   {
                       dtr[4] = item["LatitudeEnd"].ToString() + "," + item["LongitudeEnd"].ToString();
                       dtr[5] = item["LatitudeBegin"].ToString() + "," + item["LongitudeBegin"].ToString();
                   }
                   dtr[6] = string.Format("{0:N2}", float.Parse(item["Journey"].ToString()) / 1000);

                   DataTable dtNext = DistanceLogBLL.GetNextRecords(new string[]{"minuteTime",
                                                                                  "DeviceKey",
                                                                                  "ID"
                                                                    },
                                                                   new object[]{int.Parse(item["TimeMinutes"].ToString()),
                                                                                 item["DeviceKey"].ToString(),
                                                                                 double.Parse(item["ID"].ToString())
                                                                    }).Tables[0];
                   if (dtNext.Rows.Count > 0)
                   {
                       dtDataSet.Rows.Add(dtr);
                   }
               }

               if (dtDataSet.Rows.Count > 0)
               {
                   Response.ClearContent();
                   Response.Buffer = true;
                   Response.AddHeader("content-disposition", "attachment; filename=" + convertTextToFileName(Getname, "distanceall", ".xls"));
                   Response.ContentType = "application/ms-excel";

                   Response.Charset = "";
                   System.IO.StringWriter sw = new System.IO.StringWriter();
                   System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

                   var grid = new GridView();
                   grid.DataSource = dtDataSet;
                   grid.DataBind();
                   grid.RenderControl(htw);

                   Response.Output.Write(sw.ToString());
                   Response.Flush();
                   Response.End();
               }
           }
           #endregion
           #region Total distance
           else if (exceltype == "totaldistanceexcel")
           {
               List<string> listDevice = new List<string>();

               if (trackName.Length == 0)
               {
                   foreach (ENTTrackerName item in listTrackerName)
                   {
                       listDevice.Add(item.trackname);
                   }
               }
               else
               {
                   string[] listdv = trackName.Split(',');
                   foreach (string item in listdv)
                   {
                       listDevice.Add(item);
                   }
               }

               DataTable dtDataSet = setHeader("totaldistanceexcel", _language);

               foreach (string item in listDevice)
               {
                   DataTable dtDataToTime = TrackLogBLL.GetJourneyToTime(new string[]{"totime",
                                                                                       "UserName",
                                                                                       "TrackName"
                                                                          },
                                                                         new object[]{ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(totime),timezone),
                                                                                       username,
                                                                                       item
                                                                          }).Tables[0];
                   DataTable dtDataFromTime = TrackLogBLL.GetJourneyFromTime(new string[]{"fromtime",
                                                                                           "UserName",
                                                                                           "TrackName"
                                                                              },
                                                                             new object[]{ClassCommon.gpsExtensionMethod.convertGMTServerTime(DateTime.Parse(fromtime),timezone),
                                                                                           username,
                                                                                           item
                                                                              }).Tables[0];

                   if (dtDataFromTime.Rows.Count > 0 && dtDataToTime.Rows.Count > 0)
                   {
                       DataRow dtr = dtDataSet.NewRow();
                       string strFromJouneyValue = dtDataFromTime.Rows[0]["Journey"].ToString() == string.Empty ? "0" : dtDataFromTime.Rows[0]["Journey"].ToString();
                       string strToJouneyValue = dtDataToTime.Rows[0]["Journey"].ToString() == string.Empty ? "0" : dtDataToTime.Rows[0]["Journey"].ToString();
                       dtr[0] = item;
                       dtr[1] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(dtDataFromTime.Rows[0]["RecieveTime"].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                       dtr[2] = string.Format("{0:N2}", double.Parse(strFromJouneyValue) / 1000);
                       dtr[3] = ClassCommon.gpsExtensionMethod.convertGMTClientTime(DateTime.Parse(dtDataFromTime.Rows[0]["RecieveTime"].ToString()), timezone).ToString("yyyy-MM-dd hh:mm:ss tt");
                       dtr[4] = string.Format("{0:N2}", double.Parse(strToJouneyValue) / 1000);
                       dtr[5] = string.Format("{0:N2}", (double.Parse(strToJouneyValue) - double.Parse(strFromJouneyValue)) / 1000);
                       dtDataSet.Rows.Add(dtr);
                   }

                   dtDataToTime.Dispose();
                   dtDataFromTime.Dispose();
               }

               if (dtDataSet.Rows.Count > 0)
               {
                   Response.ClearContent();
                   Response.Buffer = true;
                   Response.AddHeader("content-disposition", "attachment; filename=" + convertTextToFileName(trackName, "totaldistanceexcel", ".xls"));
                   Response.ContentType = "application/ms-excel";

                   Response.Charset = "";
                   System.IO.StringWriter sw = new System.IO.StringWriter();
                   System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);

                   var grid = new GridView();
                   grid.DataSource = dtDataSet;
                   grid.DataBind();
                   grid.RenderControl(htw);

                   Response.Output.Write(sw.ToString());
                   Response.Flush();
                   Response.End();
               }
           #endregion
           }
       }

        public static DataTable setHeader(string typeName, string gpslang)
        {
            DataTable dtReturn = new DataTable();

            if (gpslang == "vi")
                gpslang = "vi-VN";

            Thread.CurrentThread.CurrentCulture = new CultureInfo(gpslang);
            CultureInfo culture = Thread.CurrentThread.CurrentCulture;

            StringBuilder stringBuilder = new StringBuilder();
            ResourceManager rm = new ResourceManager("Resources.Language", System.Reflection.Assembly.Load("App_GlobalResources"));

            string col_DeviceName = rm.GetString("col_DeviceName", culture);
            string col_AlarmType = rm.GetString("col_AlarmType", culture);
            string col_GPSTime = rm.GetString("col_GPSTime", culture);
            string col_ReceivedTime = rm.GetString("col_ReceivedTime", culture);
            string col_Fix = rm.GetString("col_Fix", culture);
            string col_Location = rm.GetString("col_Location", culture);
            string col_Latitude = rm.GetString("col_Latitude", culture);
            string col_Longitude = rm.GetString("col_Longitude", culture);
            string col_Speed = rm.GetString("col_Speed", culture);

            string colAngel = rm.GetString("colAngel", culture);
            string colDistance = rm.GetString("colDistance", culture);
            string colHDOP = rm.GetString("colHDOP", culture);
            string colHigh = rm.GetString("colHigh", culture);
            string colRunTime = rm.GetString("colRunTime", culture);
            string colSatellite = rm.GetString("colSatellite", culture);
            string colSignal = rm.GetString("colSignal", culture);

            string colEndJourney = rm.GetString("colEndJourney", culture);
            string colEndTime = rm.GetString("colEndTime", culture);
            string colJourney = rm.GetString("colJourney", culture);
            string colStartJourney = rm.GetString("colStartJourney", culture);
            string colStartTime = rm.GetString("colStartTime", culture);

            string colSpotTime = rm.GetString("colSpotTime", culture);
            string colFrom = rm.GetString("colFrom", culture);
            string colTo = rm.GetString("colTo", culture);

            if (typeName == "alarm")
            {
                dtReturn.Columns.Add(col_DeviceName);
                dtReturn.Columns.Add(col_AlarmType);
                dtReturn.Columns.Add(col_GPSTime);
                dtReturn.Columns.Add(col_ReceivedTime);
                dtReturn.Columns.Add(col_Fix);
                dtReturn.Columns.Add(col_Latitude);
                dtReturn.Columns.Add(col_Longitude);
                dtReturn.Columns.Add(col_Location);
                dtReturn.Columns.Add(col_Speed);
            }
            else if (typeName == "history")
            {
                dtReturn.Columns.Add(col_DeviceName);
                dtReturn.Columns.Add(col_GPSTime);
                dtReturn.Columns.Add(col_ReceivedTime);
                dtReturn.Columns.Add(col_Fix);
                dtReturn.Columns.Add(col_Latitude);
                dtReturn.Columns.Add(col_Longitude);
                dtReturn.Columns.Add(col_Location);
                dtReturn.Columns.Add(col_Speed);
                dtReturn.Columns.Add(col_AlarmType);
                dtReturn.Columns.Add(colHDOP);
                dtReturn.Columns.Add(colHigh);
                dtReturn.Columns.Add(colAngel);
                dtReturn.Columns.Add(colDistance);
                dtReturn.Columns.Add(colRunTime);
                dtReturn.Columns.Add(colSatellite);
                dtReturn.Columns.Add(colSignal);
            }
            else if (typeName == "totaldistanceexcel")
            {
                dtReturn.Columns.Add(col_DeviceName);
                dtReturn.Columns.Add(colStartTime);
                dtReturn.Columns.Add(colStartJourney);
                dtReturn.Columns.Add(colEndTime);
                dtReturn.Columns.Add(colEndJourney);
                dtReturn.Columns.Add(colJourney);
            }
            else if (typeName == "parkingall")
            {
                dtReturn.Columns.Add(col_DeviceName);
                dtReturn.Columns.Add(colStartTime);
                dtReturn.Columns.Add(colEndTime);
                dtReturn.Columns.Add(col_Latitude);
                dtReturn.Columns.Add(col_Longitude);
                dtReturn.Columns.Add(col_Location);
                dtReturn.Columns.Add(colSpotTime);
            }
            else if (typeName == "distanceall")
            {
                dtReturn.Columns.Add(col_DeviceName);
                dtReturn.Columns.Add(colStartTime);
                dtReturn.Columns.Add(colEndTime);
                dtReturn.Columns.Add(colSpotTime);
                dtReturn.Columns.Add(colFrom);
                dtReturn.Columns.Add(colTo);
                dtReturn.Columns.Add(colDistance);
            }
            // return stringBuilder.ToString();
            return dtReturn;
        }

        public static string getResouceByName(string resouceName, string gpslang)
        {
            if (gpslang == "vi")
                gpslang = "vi-VN";

            Thread.CurrentThread.CurrentCulture = new CultureInfo(gpslang);
            CultureInfo culture = Thread.CurrentThread.CurrentCulture;

            StringBuilder stringBuilder = new StringBuilder();
            ResourceManager rm = new ResourceManager("Resources.Language", System.Reflection.Assembly.Load("App_GlobalResources"));

            return rm.GetString(resouceName, culture);
        }

        public static string convertTextToFileName(string inputString, string typeAlarm, string fileType)
        {
            StringBuilder strBuilder = new StringBuilder();
            inputString = inputString.Replace(" ", "");
            inputString = inputString.Replace(",", "_");
            strBuilder.Append(typeAlarm + "_");
            strBuilder.Append(inputString + "_");
            strBuilder.Append(DateTime.Now.ToString("yyyy-MM-dd-mm-hh-ss-tt"));
            strBuilder.Append(fileType);
            return HttpUtility.UrlEncode(strBuilder.ToString(), System.Text.Encoding.UTF8);
        }

    }
}
